home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / jmodm308.arc / JMODEM.H < prev    next >
Text File  |  1991-01-02  |  23KB  |  302 lines

  1. /****************************************************************************/
  2. /*   FILE JMODEM.H                                                          */
  3. /*   Created 11-JAN-1990                Richard B. Johnson                  */
  4. /*                                      405 Broughton Drive                 */
  5. /*                                      Beverly, Massachusetts 01915        */
  6. /*                                      BBS (508) 922-3166                  */
  7. /*                                                                          */
  8. /*    This program requires about 67k of free RAM to execute properly.      */
  9. /*    If you have 66k or less, it will execute, but the screens will        */
  10. /*    not be written or replaced properly. If you have only 64k, the        */
  11. /*    program will exit with an error message.                              */
  12. /*                                                                          */
  13. /*    Revision History:                                                     */
  14. /*    V3.00   Beta test                  11-FEB-1990   Richard B. Johnson   */
  15. /*    V3.01   First release              18-FEB-1990   Richard B. Johnson   */
  16. /*    V3.02   Revised                    19-FEB-1990   Richard B. Johnson   */
  17. /*                                                                          */
  18. /*      (1)   A bug in MicroSoft _calloc()  allocates overlapping           */
  19. /*            buffers so data files were getting corrupted. I had           */
  20. /*            used both _calloc() and _malloc() at the same time and        */
  21. /*            they didn't like it. I changed the memory allocation          */
  22. /*            to _malloc() only and it seems to work okay.                  */
  23. /*                                                                          */
  24. /*      (2)   While debugging, I found some structures I didn't need and    */
  25. /*            removed them. Changed some code to accommodate.               */
  26. /*                                                                          */
  27. /*      (3)   Added a file-size during downloads.                           */
  28. /*                                                                          */
  29. /*      (4)   Changed code in the data encoding (compression) routine       */
  30. /*            in an attempt to speed it up.                                 */
  31. /*                                                                          */
  32. /*    V3.03   Revised                   20-FEB-1990  Richard B. Johnson     */
  33. /*                                                                          */
  34. /*      (5)   Fixed bug in compression routine where the loop wasn't        */
  35. /*            terminating properly, adding random characters. Bug was       */
  36. /*            created during V3.02 change.                                  */
  37. /*                                                                          */
  38. /*    V3.04   Revised                   27-FEB-1990  Richard B. Johnson     */
  39. /*                                                                          */
  40. /*      (1)   Modified the block-size routine and the receive-block         */
  41. /*            routine in an attempt to improve the noise immunity.          */
  42. /*            Does not abort even if you whistle into the telephone         */
  43. /*            during uploads and downloads. Waits 5 seconds to clear        */
  44. /*            the interrupt buffer when a bad block-size is received.       */
  45. /*                                                                          */
  46. /*      (2)   Added a 1/2 second wait for modem status when opening         */
  47. /*            channel. This might accommodate slow modems response to       */
  48. /*            RTS.                                                          */
  49. /*                                                                          */
  50. /*    V3.05   Revised                   22-MAR-1990  Richard B. Johnson     */
  51. /*                                                                          */
  52. /*      (1)   Removed _sprintf() runtime library calls to shorten           */
  53. /*            the code. Saved about 4k.                                     */
  54. /*                                                                          */
  55. /*      (2)   Removed extra spaces in the signon-logo to shorten            */
  56. /*            the program size.                                             */
  57. /*                                                                          */
  58. /*      (3)   Changed the method of creating a fixed-length string          */
  59. /*            for both the block size and cps numbers which saved about     */
  60. /*            800 bytes of program size.                                    */
  61. /*                                                                          */
  62. /*      (4)   Changed numerous array indexes in JMODEM_F.C to pointers      */
  63. /*            to reduce code size. Saved a few hundred bytes and should     */
  64. /*            improve speed of screen output.                               */
  65. /*                                                                          */
  66. /*      (5)   Created a local _puts() routine which saved over 6k from the  */
  67. /*            MicroSoft C runtime library version. (JMODEM_F.C)             */
  68. /*                                                                          */
  69. /*    V3.06   Revised                   07-APR-1990  Richard B. Johnson     */
  70. /*                                                                          */
  71. /*      (1)   Put the filename text into the syst structure as a pointer    */
  72. /*            to char. This allowed me to save 56 bytes of code and now     */
  73. /*            only two parameters are passed to the _screen() function.     */
  74. /*                                                                          */
  75. /*      (2)   Modified the syst structure and supporting code.              */
  76. /*                                                                          */
  77. /*      (3)   Moved all external data and functions to the JMODEM.H file.   */
  78. /*                                                                          */
  79. /*      (4)   Moved _disp() "usage" module to JMODEM_F.C                    */
  80. /*                                                                          */
  81. /*      (5)   Changed arrays in JMODEM_B.C to pointers to reduce code-      */
  82. /*            size. Eliminated _strcpy() from the command-line parsing      */
  83. /*            routines. Brought the code-size to less than 12,000 bytes.    */
  84. /*                                                                          */
  85. /*      (6)   Reduced the code-size in the _encode(), _decode(), and        */
  86. /*            _crc() routines in JMODEM_D.C. Removed shifts to improve      */
  87. /*            speed and replaced the shifts with pointers for altering      */
  88. /*            portions of the strings.                                      */
  89. /*                                                                          */
  90. /*      (7)   Made a _cancel() routine in JMODEM_A.C to send ^Xes upon      */
  91. /*            abort.                                                        */
  92. /*                                                                          */
  93. /*      (8)   Removed the bit being set "OUT 1" via the modem-control       */
  94. /*            register in the "open" routine in JMODEM_E.C. This was        */
  95. /*            causing some internal modems to lock up as they use this      */
  96. /*            bit for something. "OUT 2" is used to enable IRQ on most      */
  97. /*            clone RS-232 boards and modems. The Heathkit HZ-100 boards    */
  98. /*            will probably not work anymore because they use "OUT 1".      */
  99. /*                                                                          */
  100. /*    V3.07   Revised                   03-MAY-1990  Richard B. Johnson     */
  101. /*                                                                          */
  102. /*      (1)   Rewrote code to remove the requirement for a file buffer.     */
  103. /*            This means that this buffer does not need to be allocated,    */
  104. /*            saving about 8k of RAM at run-time.  ( JMODEM_A.C )           */
  105. /*                                                                          */
  106. /*            Program now only requires 52k of free RAM to execute okay.    */
  107. /*                                                                          */
  108. /*      (2)   Changed the header file, JMODEM.H, and function calling       */
  109. /*            procedures to file_io() and screen() to allow variable-       */
  110. /*            length parameter-lists. This eliminates the requirement       */
  111. /*            to pass a NULL as a place-holder on procedures that don't     */
  112. /*            always require all possible parameters to be passed. This     */
  113. /*            saved about 50 bytes of code.                                 */
  114. /*                                                                          */
  115. /*      (3)   Changed the "Usage" prompt and code to reduce program size.   */
  116. /*            Saved about 60 bytes.                                         */
  117. /*                                                                          */
  118. /*      (4)   Changed keyboard break interrupt in JMODEM_E.C so it sets     */
  119. /*            the global timer to zero as well as setting the abort flag.   */
  120. /*                                                                          */
  121. /*    V3.08   Revised                   01-DEC-1991  Richard B. Johnson     */
  122. /*                                                                          */
  123. /*      (1)   Changed the code to compile without warning errors when       */
  124. /*            using Microsoft Version 6.0. They saw fit to change the       */
  125. /*            ANSI standards for declaring objects passed to functions.     */
  126. /*            The new "standards" were called to my attention by            */
  127. /*            Jeff Jevnisek who provided modified source.                   */
  128. /*                                                                          */
  129. /*      (2)   Changed the method of determining a memory allocation         */
  130. /*            failure. The code used to check for a NULL pointer returned   */
  131. /*            from _malloc() if memory was not available. Microsoft does    */
  132. /*            not allow NULL to be used for that anymore! Instead I have    */
  133. /*            to either use a cast or check for (!ptr). I chose the latter. */
  134. /*                                                                          */
  135. /*                                                                          */
  136. /****************************************************************************/
  137. /*                  Parameters that are specific to JMODEM                  */
  138. /****************************************************************************/
  139. #define VERS            "Version 3.08"      /* Version number               */
  140. #define _8K             0x2000              /* 4096 bytes                   */
  141. #define BLK_SIZ         0x200               /* Starting block size          */
  142. #define OVRHD           0x06                /* Private, JMODEM overhead     */
  143. #define DAT_LEN         _8K + 0x400         /* Data buffer length           */
  144. #define DAT_MAX         _8K                 /* Max block length             */
  145. #define OPEN_READ       0x01                /* Private OPEN file function   */
  146. #define CREATE          0x02                /* Private CREATE file function */
  147. #define WRITE           0x03                /* Private WRITE file function  */
  148. #define CLOSE           0x04                /* Private CLOSE file function  */
  149. #define DELETE          0x05                /* Private DELETE file function */
  150. #define READ            0x06                /* Private READ file function   */
  151. #define GET_CRC         0x00                /* Private Get CRC function     */
  152. #define SET_CRC         0x01                /* Private Set CRC function     */
  153. #define NORM            0x01                /* Private, show normal data    */
  154. #define COMP            0x02                /* Private, show compressed     */
  155. #define EOF_            0x04                /* Private, show end of file    */
  156. #define TIMOUT          0x5A                /* Timeout (ticks) for read     */
  157. #define EOT             0x04                /* "D" - 64                     */
  158. #define ACK             0x06                /* "F" - 64                     */
  159. #define NAK             0x15                /* "U" - 64                     */
  160. #define SYN             0x16                /* "V" - 64                     */
  161. #define CAN             0x18                /* "X" - 64                     */
  162. #define SCR_SGN         0x01                /* Signon screen                */
  163. #define SCR_BOX         0x02                /* Write box on the screen      */
  164. #define SCR_TXT         0x03                /* Write text to x/y address    */
  165. #define SCR_STA         0x04                /* Write status box             */
  166. #define SCR_FIL         0x05                /* Write open file box          */
  167. #define SCR_FOK         0x06                /* File open okay               */
  168. #define SCR_FNF         0x07                /* File not found               */
  169. #define SCR_FCR         0x08                /* Can't create the file        */
  170. #define SCR_FRN         0x09                /* Renamed the file             */
  171. #define SCR_SYS         0x0A                /* Show system parameters       */
  172. #define SCR_SYT         0x0B                /* Show trans synchronization   */
  173. #define SCR_SYR         0x0C                /* Show Receive synchronization */
  174. #define SCR_FLG         0x0D                /* Show status flag             */
  175. #define SCR_END         0x0E                /* Exit all screens             */
  176. #define JM_NRM          0x00                /* Normal exit                  */
  177. #define JM_FNF          0x01                /* File not found               */
  178. #define JM_REN          0x02                /* Can't rename the file        */
  179. #define JM_CRE          0x03                /* Can't create the file        */
  180. #define JM_MEM          0x04                /* No memory available          */
  181. #define JM_CAR          0x05                /* Modem carrier failed         */
  182. #define JM_SYN          0x06                /* Can't synchronize            */
  183. #define JM_ABT          0x07                /* Aborted                      */
  184. #define JM_CMD          0x08                /* Command-line error           */
  185. #define JM_TIM          0x09                /* Time-out                     */
  186. #define JM_FAT          0x0A                /* Fatal error                  */
  187. #define JM_MAX          0xFFFF              /* Maximum buffer space exceeded*/
  188. #define byte unsigned char                  /* Make code readable           */
  189. #define word unsigned short int             /* Make code readable           */
  190. #define ulong unsigned long int             /* Make code readable           */
  191. /****************************************************************************/
  192. /*                     Structures and templates                             */
  193. /****************************************************************************/
  194. typedef struct
  195.         {                                   /* Structure for JMODEM status  */
  196.         word  s_blk;                        /* Block being sent / received  */
  197.         word  s_len;                        /* Length of the block          */
  198.         ulong s_byt;                        /* Bytes so far                 */
  199.         word  s_cps;                        /* Speed, characters / second   */
  200.         byte  *s_sta;                       /* Pointer to current status    */
  201.         byte  *s_txt;                       /* Pointer to information text  */
  202.         } SYS;
  203.  
  204. typedef struct                             /* JMODEM block header structure */
  205.         {
  206.         word len;                          /* Block length                  */
  207.         byte blk_typ;                      /* Kind of block EOF, COMP, etc  */
  208.         byte blk_num;                      /* Block number (starts at 1 )   */
  209.         byte blk_dat;                      /* First data character          */
  210.         } JBUF;
  211.  
  212. /****************************************************************************/
  213. /*                   External function prototypes                           */
  214. /****************************************************************************/
  215. #ifdef SCREEN
  216.     extern void screen(short, SYS *);       /* Function (in SCREEN.H)       */
  217. #else
  218.     extern void screen(short,...);          /* Show variable length list    */
  219. #endif
  220.  
  221. extern word open_chan(                      /* Open communications channel  */
  222.                 word);                      /* Communications port number   */
  223. extern word close_chan(                     /* Close communications channel */
  224.                 word);                      /* Communications port number   */
  225. extern word read_chan(                      /* Read communications channel  */
  226.                 word,                       /* Bytes to read                */
  227.                 byte *);                    /* Pointer to the buffer        */
  228. extern word write_chan(                     /* Write communications channel */
  229.                 word,                       /* Bytes to write (send)        */
  230.                 byte *);                    /* Pointer to the buffer        */
  231. extern word send_blk(                       /* Send JMODEM block            */
  232.                 word,                       /* Block length                 */
  233.                 SYS *,                      /* Pointer to status structure  */
  234.                 byte *);                    /* Pointer to the data buffer   */
  235. extern word recv_blk(                       /* Receive JMODEM block         */
  236.                 word *,                     /* Pointer to the block length  */
  237.                 byte *);                    /* Pointer to the data buffer   */
  238. extern word encode(                         /* Compress the data            */
  239.                 word,                       /* Length of the input data     */
  240.                 byte *,                     /* Pointer to the input buffer  */
  241.                 byte *);                    /* Pointer to the output buffer */
  242. extern word decode(                         /* Expand compressed data       */
  243.                 word,                       /* Data length                  */
  244.                 byte *,                     /* Pointer to the input buffer  */
  245.                 byte *);                    /* Pointer to the output buffer */
  246. extern word calc_crc(                       /* Calculate CRC                */
  247.                 word,                       /* Function, GET or SET         */
  248.                 word,                       /* Length of the data buffer    */
  249.                 byte *);                    /* Pointer to the data buffer   */
  250.  
  251. #ifdef FILE_IO
  252.     extern word file_io(                    /* File I/O                     */
  253.                 word,                       /* Function code                */
  254.                 short *,                    /* Pointer to the file handle   */
  255.                 byte *,                     /* Pointer to the buffer        */
  256.                 word);                      /* Data buffer length           */
  257. #else
  258.     extern word file_io(                    /* File I/O                     */
  259.                 word,                       /* Function code                */
  260.                 short *,...);               /* Variable length param list   */
  261. #endif
  262.  
  263. extern byte *get_inp(                       /* Get input file-name          */
  264.                 word,                       /* Number of arguments          */
  265.                 char **);                   /* Pointer to list of pointers  */
  266. extern byte get_fun(                        /* Get function (S or R)        */
  267.                 word,                       /* Number of arguments          */
  268.                 char **);                   /* Pointer to command strings   */
  269. extern word get_port(                       /* Get port (1 - 4)             */
  270.                 word,                       /* Number of arguments          */
  271.                 char **);                   /* Pointer to command strings   */
  272. extern void disp(void);                     /* Display 'usage' message      */
  273. extern byte *allocate_memory(               /* Allocate memory              */
  274.                 word);                      /* Bytes to allocate            */
  275. extern void flush (void);                   /* Flush the interrupt buffer   */
  276. extern void cancel(void);                   /* Send ^Xes to cancel transfer */
  277. extern word tx_sync(void);                  /* Synchronize during transmit  */
  278. extern word rx_sync(void);                  /* Synchronize during receive   */
  279. /****************************************************************************/
  280. /*                   Global variables and structures                        */
  281. /****************************************************************************/
  282. extern byte *int_buffer;                    /* pointer to interrupt buffer  */
  283. extern word user_abort;                     /* User abort flag              */
  284. extern word port;                           /* Port number                  */
  285. extern word timer;                          /* Global timer                 */
  286. extern byte abrt[];                         /* Six messages in JMODEM_F.C   */
  287. extern byte okay[];
  288. extern byte retry[];
  289. extern byte done[];
  290. extern byte flow[];
  291. extern byte malfail[];
  292. extern SYS syst;                            /* Structure in JMODEM_A.C      */
  293. /****************************************************************************/
  294. /*                         Preprocessor directives                          */
  295. /****************************************************************************/
  296. #pragma intrinsic (inp, outp)               /* Generate in-line code here   */
  297. #pragma intrinsic (_disable, _enable)
  298. #pragma intrinsic (memcpy, _rotl)
  299. #pragma check_stack(off)                   /* No checking between functions */
  300. /****************************************************************************/
  301. /*********************** E N D  OF  M O D U L E *****************************/
  302.